#include "score.h"
#include "Judge.h"
#include "GobangDoc.h"
#include "match.h"

Judge::Judge(CGobangDoc* doc):pDoc(doc){
}

inline Score Judge::evaluate(int x,int y,BoardState color){
	if(hasGB1(x,y,color)){
		return GB_1;
	}
	if(hasGB2(x,y,color)){
		return GB_2;
	}
	if(hasGB3(x,y,color)){
		return GB_3;
	}
	if(hasGB4(x,y,color)){
		return GB_4;
	}
	if(hasGB5(x,y,color)){
		return GB_5;
	}
	if(hasGB6(x,y,color)){
		return GB_6;
	}
	if(hasGB7(x,y,color)){
		return GB_8;
	}
	if(hasGB8(x,y,color)){
		return GB_8;
	}
	if(hasGB9(x,y,color)){
		return GB_9;
	}
	if(hasGB10(x,y,color)){
		return GB_10;
	}
	if(hasGB11(x,y,color)){
		return GB_11;
	}
	if(hasGB12(x,y,color)){
		return GB_12;
	}
	if(hasGB13(x,y,color)){
		return GB_13;
	}
	if(hasGB14(x,y,color)){
		return GB_14;
	}
	if(hasGB15(x,y,color)){
		return GB_15;
	}
	if(hasGB16(x,y,color)){
		return GB_16;
	}
	return GB_GENERAL;
}

inline bool Judge::hasGB1(int x,int y,BoardState color){
	if(color==WHITE){
		if(pDoc->CheckResult(x,y)==WHITE_WIN){
			return true;
		}
		else{
			return false;
		}
	}

	if(color==BLACK){
		if(pDoc->CheckResult(x,y)==BLACK_WIN){
			return true;	
		}
		else{
			return false;
		}
	}
}

bool Judge::hasGB2(int x,int y,BoardState color){
	BoardState pattern[6];
	BoardState src[9];
	bool rst=false;

	pattern[0]=EMPTY;
	pattern[1]=color;
	pattern[2]=color;
	pattern[3]=color;
	pattern[4]=color;
	pattern[5]=EMPTY;

	int offset=0;
	int i=0;

	for(offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			src[i]=pDoc->GetBoardState(x+offset,y);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	for(offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			src[i]=pDoc->GetBoardState(x,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst ||  match(src,pattern,9,6);

	for(offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			src[i]=pDoc->GetBoardState(x+offset,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst ||  match(src,pattern,9,6);

	for(offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			src[i]=pDoc->GetBoardState(x+offset,y-offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	return rst;
}

bool Judge::hasGB3(int x,int y,BoardState color){
	BoardState pattern[6];
	BoardState src[8];
	bool rst=false;

	pattern[0]=EMPTY;
	pattern[1]=color;
	pattern[2]=color;
	pattern[3]=color;
	pattern[4]=EMPTY;
	pattern[5]=EMPTY;

	for(int offset=-3,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			src[i]=pDoc->GetBoardState(x+offset,y);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	for(int offset=-3,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			src[i]=pDoc->GetBoardState(x,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	for(int offset=-3,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			src[i]=pDoc->GetBoardState(x+offset,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	for(int offset=-3,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			src[i]=pDoc->GetBoardState(x+offset,y-offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	return rst;
}

bool Judge::hasGB4(int x,int y,BoardState color){
	BoardState pattern[6];
	BoardState src[8];
	bool rst=false;

	pattern[0]=EMPTY;
	pattern[1]=EMPTY;
	pattern[2]=color;
	pattern[3]=color;
	pattern[4]=color;
	pattern[5]=EMPTY;

	for(int offset=-4,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			src[i]=pDoc->GetBoardState(x+offset,y);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	for(int offset=-4,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			src[i]=pDoc->GetBoardState(x,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	for(int offset=-4,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			src[i]=pDoc->GetBoardState(x+offset,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	for(int offset=-4,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			src[i]=pDoc->GetBoardState(x+offset,y-offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	return rst;
}

bool Judge::hasGB5(int x,int y,BoardState color){
	BoardState pattern[6];
	BoardState src[9];
	bool rst=false;

	pattern[0]=EMPTY;
	pattern[1]=color;
	pattern[2]=color;
	pattern[3]=EMPTY;
	pattern[4]=color;
	pattern[5]=EMPTY;

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			src[i]=pDoc->GetBoardState(x+offset,y);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			src[i]=pDoc->GetBoardState(x,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			src[i]=pDoc->GetBoardState(x+offset,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			src[i]=pDoc->GetBoardState(x+offset,y-offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	return rst;
}

bool Judge::hasGB6(int x,int y,BoardState color){
	BoardState pattern[6];
	BoardState src[9];
	bool rst=false;

	pattern[0]=EMPTY;
	pattern[1]=color;
	pattern[2]=EMPTY;
	pattern[3]=color;
	pattern[4]=color;
	pattern[5]=EMPTY;

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			src[i]=pDoc->GetBoardState(x+offset,y);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			src[i]=pDoc->GetBoardState(x,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			src[i]=pDoc->GetBoardState(x+offset,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			src[i]=pDoc->GetBoardState(x+offset,y-offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	return rst;
}

bool Judge::hasGB7(int x,int y,BoardState color){
	BoardState pattern[6];
	BoardState src[9];
	bool rst=false;

	pattern[0]=ERROR;
	pattern[1]=color;
	pattern[2]=color;
	pattern[3]=color;
	pattern[4]=color;
	pattern[5]=EMPTY;

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			if(pDoc->GetBoardState(x+offset,y)==color||pDoc->GetBoardState(x+offset,y)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			if(pDoc->GetBoardState(x,y+offset)==color||pDoc->GetBoardState(x,y+offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x,y+offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			if(pDoc->GetBoardState(x+offset,y+offset)==color||pDoc->GetBoardState(x+offset,y+offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y+offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			if(pDoc->GetBoardState(x+offset,y-offset)==color||pDoc->GetBoardState(x+offset,y-offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y-offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	return rst;
}

bool Judge::hasGB8(int x,int y,BoardState color){
	BoardState pattern[6];
	BoardState src[9];
	bool rst=false;

	pattern[0]=EMPTY;
	pattern[1]=color;
	pattern[2]=color;
	pattern[3]=color;
	pattern[4]=color;
	pattern[5]=ERROR;

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			if(pDoc->GetBoardState(x+offset,y)==color||pDoc->GetBoardState(x+offset,y)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			if(pDoc->GetBoardState(x,y+offset)==color||pDoc->GetBoardState(x,y+offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x,y+offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			if(pDoc->GetBoardState(x+offset,y+offset)==color||pDoc->GetBoardState(x+offset,y+offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y+offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	for(int offset=-4,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			if(pDoc->GetBoardState(x+offset,y-offset)==color||pDoc->GetBoardState(x+offset,y-offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y-offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,9,6);

	return rst;
}

bool Judge::hasGB9(int x,int y,BoardState color){
	BoardState pattern[7];
	BoardState src[11];
	bool rst=false;

	pattern[0]=ERROR;
	pattern[1]=color;
	pattern[2]=color;
	pattern[3]=EMPTY;
	pattern[4]=color;
	pattern[5]=color;
	pattern[6]=ERROR;

	for(int offset=-5,i=0;offset<=5;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			if(pDoc->GetBoardState(x+offset,y)==color||pDoc->GetBoardState(x+offset,y)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,11,7);

	for(int offset=-5,i=0;offset<=5;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			if(pDoc->GetBoardState(x,y+offset)==color||pDoc->GetBoardState(x,y+offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x,y+offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,11,7);

	for(int offset=-5,i=0;offset<=5;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			if(pDoc->GetBoardState(x+offset,y+offset)==color||pDoc->GetBoardState(x+offset,y+offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y+offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,11,7);

	for(int offset=-5,i=0;offset<=5;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			if(pDoc->GetBoardState(x+offset,y-offset)==color||pDoc->GetBoardState(x+offset,y-offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y-offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,11,7);

	return rst;
}

bool Judge::hasGB10(int x,int y,BoardState color){
	BoardState pattern[7];
	BoardState src[11];
	bool rst=false;

	pattern[0]=ERROR;
	pattern[1]=color;
	pattern[2]=EMPTY;
	pattern[3]=color;
	pattern[4]=color;
	pattern[5]=color;
	pattern[6]=ERROR;

	for(int offset=-5,i=0;offset<=5;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			if(pDoc->GetBoardState(x+offset,y)==color||pDoc->GetBoardState(x+offset,y)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,11,7);

	for(int offset=-5,i=0;offset<=-5;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			if(pDoc->GetBoardState(x,y+offset)==color||pDoc->GetBoardState(x,y+offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x,y+offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,11,7);

	for(int offset=-5,i=0;offset<=5;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			if(pDoc->GetBoardState(x+offset,y+offset)==color||pDoc->GetBoardState(x+offset,y+offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y+offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,11,7);

	for(int offset=-5,i=0;offset<=5;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			if(pDoc->GetBoardState(x+offset,y-offset)==color||pDoc->GetBoardState(x+offset,y-offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y-offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,11,7);

	return rst;
}

bool Judge::hasGB11(int x,int y,BoardState color){
	BoardState pattern[7];
	BoardState src[11];
	bool rst=false;

	pattern[0]=ERROR;
	pattern[1]=color;
	pattern[2]=color;
	pattern[3]=color;
	pattern[4]=EMPTY;
	pattern[5]=color;
	pattern[6]=ERROR;

	for(int offset=-5,i=0;offset<=5;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			if(pDoc->GetBoardState(x+offset,y)==color||pDoc->GetBoardState(x+offset,y)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,11,7);

	for(int offset=-5,i=0;offset<=5;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			if(pDoc->GetBoardState(x,y+offset)==color||pDoc->GetBoardState(x,y+offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x,y+offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,11,7);

	for(int offset=-5,i=0;offset<=5;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			if(pDoc->GetBoardState(x+offset,y+offset)==color||pDoc->GetBoardState(x+offset,y+offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y+offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,11,7);

	for(int offset=-5,i=0;offset<=5;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			if(pDoc->GetBoardState(x+offset,y-offset)==color||pDoc->GetBoardState(x+offset,y+offset)==EMPTY){
				src[i]=pDoc->GetBoardState(x+offset,y-offset);
			}
			else{
				src[i]=ERROR;
			}
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,11,7);

	return rst;
}

bool Judge::hasGB12(int x,int y,BoardState color){
	BoardState pattern[6];
	BoardState src[7];
	bool rst=false;

	pattern[0]=EMPTY;
	pattern[1]=EMPTY;
	pattern[2]=color;
	pattern[3]=color;
	pattern[4]=EMPTY;
	pattern[5]=EMPTY;

	for(int offset=-3,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			src[i]=pDoc->GetBoardState(x+offset,y);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,7,6);

	for(int offset=-3,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			src[i]=pDoc->GetBoardState(x,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,7,6);

	for(int offset=-3,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			src[i]=pDoc->GetBoardState(x+offset,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,7,6);

	for(int offset=-3,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			src[i]=pDoc->GetBoardState(x+offset,y-offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,7,6);

	return rst;
}

bool Judge::hasGB13(int x,int y,BoardState color){
	BoardState pattern[6];
	BoardState src[8];
	bool rst=false;

	pattern[0]=EMPTY;
	pattern[1]=EMPTY;
	pattern[2]=color;
	pattern[3]=EMPTY;
	pattern[4]=color;
	pattern[5]=EMPTY;

	for(int offset=-4,i=0;offset<4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			src[i]=pDoc->GetBoardState(x+offset,y);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	for(int offset=-4,i=0;offset<4;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			src[i]=pDoc->GetBoardState(x,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	for(int offset=-4,i=0;offset<4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			src[i]=pDoc->GetBoardState(x+offset,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	for(int offset=-4,i=0;offset<4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			src[i]=pDoc->GetBoardState(x+offset,y-offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	return rst;
}

bool Judge::hasGB14(int x,int y,BoardState color){
	BoardState pattern[6];
	BoardState src[8];
	bool rst=false;

	pattern[0]=EMPTY;
	pattern[1]=color;
	pattern[2]=EMPTY;
	pattern[3]=color;
	pattern[4]=EMPTY;
	pattern[5]=EMPTY;

	for(int offset=-3,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			src[i]=pDoc->GetBoardState(x+offset,y);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	for(int offset=-3,i=0;offset<=4;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			src[i]=pDoc->GetBoardState(x,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	for(int offset=-3,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			src[i]=pDoc->GetBoardState(x+offset,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	for(int offset=-3,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			src[i]=pDoc->GetBoardState(x+offset,y-offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	return rst;
}

bool Judge::hasGB15(int x,int y,BoardState color){
	BoardState pattern[6];
	BoardState src[6];
	bool rst=false;

	pattern[0]=EMPTY;
	pattern[1]=EMPTY;
	pattern[2]=EMPTY;
	pattern[3]=color;
	pattern[4]=EMPTY;
	pattern[5]=EMPTY;

	for(int offset=-3,i=0;offset<3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			src[i]=pDoc->GetBoardState(x+offset,y);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,6,6);

	for(int offset=-3,i=0;offset<3;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			src[i]=pDoc->GetBoardState(x,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,6,6);

	for(int offset=-3,i=0;offset<3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			src[i]=pDoc->GetBoardState(x+offset,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,6,6);

	for(int offset=-3,i=0;offset<3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			src[i]=pDoc->GetBoardState(x+offset,y-offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,6,6);

	return rst;
}

bool Judge::hasGB16(int x,int y,BoardState color){
	BoardState pattern[6];
	BoardState src[6];
	bool rst=false;

	pattern[0]=EMPTY;
	pattern[1]=EMPTY;
	pattern[2]=color;
	pattern[3]=EMPTY;
	pattern[4]=EMPTY;
	pattern[5]=EMPTY;

	for(int offset=-2,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y)){
			src[i]=pDoc->GetBoardState(x+offset,y);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,6,6);

	for(int offset=-2,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x,y+offset)){
			src[i]=pDoc->GetBoardState(x,y+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,8,6);

	for(int offset=-2,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y+offset)){
			src[i]=pDoc->GetBoardState(x+offset,x+offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,6,6);

	for(int offset=-2,i=0;offset<=3;++offset,++i){
		if(pDoc->CheckBoarder(x+offset,y-offset)){
			src[i]=pDoc->GetBoardState(x+offset,y-offset);
		}
		else{
			src[i]=ERROR;
		}
	}

	rst = rst || match(src,pattern,6,6);

	return rst;
}
